package scheduler;

import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;

public class LinkRepository implements ILinkRepository
{
	
	private List<String> _usedLinkList=new LinkedList<String>(); 
	private BlockingQueue<String> _toParseLinkQueue=new LinkedBlockingQueue<String>();
	
	LinkRepository(List<String> toParselinkList)
	{
		this._toParseLinkQueue.addAll(toParselinkList);
	}
	
	public synchronized void saveLinks(List<String> linklist)
	{
		for(String s:linklist){
			if(!this._usedLinkList.contains(s) && !this._toParseLinkQueue.contains(s)) this._toParseLinkQueue.offer(s);
		}
	}
	
	public synchronized String getLink()
	{
		String link=null;
		try {
			link=this._toParseLinkQueue.take();
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		this._usedLinkList.add(link);
		return link;
	}
}
